package com.yh.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yh.bean.Log;
import com.yh.dao.LogDao;
import com.yh.service.LogService;

@Service
public class LogServiceImpl implements LogService {

	@Resource
	private LogDao logDao;
	
	@Override
	public boolean addLogInfo(Log log) {
		//1.调用 dao层方法向数据库添加日志记录信息
		int result =logDao.insertLogInfo(log);
		if(result !=0){
			System.out.println("=====已经成功插入一条日志记录=====");
			return true;
		}else{
			return false;
		}

	}

	@Override
	public Map<String, Object> getLogLists(Map<String, Object> map) {
		
		int currentPage = (int) map.get("currentPage");
		int pageNum = (int) map.get("pageNum");
		//1.使用mybatis pageHelper 来进行分页查找所有的list 集合 注意一定要写到查询之前
		PageHelper.startPage(currentPage, pageNum);//返回值是一个page 对象，可以不使用
		//2.调用dao层方法进行查询
		List<Log> loglist=logDao.getLogs(map);
		//3.调用pageInfo 对象获取总记录数信息
		PageInfo<Log> info = new PageInfo<Log>(loglist);
		int totalPages = (int) info.getTotal();
		//4.存入map集合中
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("count", totalPages);
		map2.put("data", loglist);
		return map2;
	}

	@Override
	public int batchDeleteLogs(List<Log> logs) {
		//调用dao层方法删除批量删除
		int result = logDao.deleteLogList(logs);
		return result;
	}

}
